package com.example.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.example.demo.entity.Goods;
import com.example.demo.utils.PageResult;
import com.example.demo.utils.PassToken;
import com.example.demo.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.demo.entity.Category;
import com.example.demo.service.ICategoryService;
import com.example.demo.utils.PageUtils;
import com.example.demo.utils.PageResult;

/**
 * systemController
 * 
 * @author ruoyi
 * @date 2025-04-01
 */
@RestController
@RequestMapping("/system/category")
public class CategoryController
{
    @Autowired
    private ICategoryService categoryService;

    /**
     * 查询system列表
     */
    @PassToken
    @GetMapping("/list")
    public ResponseResult list(Category category, @RequestParam(defaultValue = "1")int pageNum,@RequestParam(defaultValue = "10") int pageSize)
    {
        PageResult pageResult= categoryService.selectCategoryList(category,pageNum, pageSize);
//        startPage();

        return ResponseResult.createBySuccess(200,pageResult,"查询成功");
    }

    @PassToken
    @GetMapping("/list1")
    public ResponseResult list1(Category category, @RequestParam(defaultValue = "1")int pageNum,@RequestParam(defaultValue = "20") int pageSize)
    {
        PageResult pageResult= categoryService.selectCategoryGoodsList(category,pageNum, pageSize);
//        startPage();

        return ResponseResult.createBySuccess(200,pageResult,"查询成功");
    }





    /**
     * 获取system详细信息
     */

    @GetMapping(value = "/{cid}")
    public  ResponseResult getInfo(@PathVariable("cid") Long cid)
    {
         Category category=categoryService.selectCategoryByCid(cid);
        return  ResponseResult.createBySuccess(200,category,"查询成功");
    }

    /**
     * 新增system
     */

    @PostMapping
    public ResponseResult  add(@RequestBody Category category)
    {

        int i=categoryService.insertCategory(category);
        if(i>0){
            return ResponseResult.createBySuccess(200,"","添加成功");
        }else {
            return ResponseResult.createByFail(500, "添加失败");
        }
    }

    /**
     * 修改system
     */


    @PutMapping
    public  ResponseResult edit(@RequestBody Category category)
    {
        int i=categoryService.updateCategory(category);
        if(i>0){
            return ResponseResult.createBySuccess(200,"","更新成功");
        }else {
            return ResponseResult.createByFail(500, "更新失败");
        }
    }

    /**
     * 删除system
     */

	@DeleteMapping("/{cids}")
    public ResponseResult remove(@PathVariable Long[] cids)
    {
        int i=categoryService.deleteCategoryByCids(cids);
        if(i>0){
            return ResponseResult.createBySuccess(200,"","删除成功");
        }else {
            return ResponseResult.createByFail(500, "删除失败");
        }
    }
}
